package com.system.interceptor;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
import com.system.property.WXProperty;
import com.system.redis.RedisDao;
/**
 * 微信登陆拦截器(验证自定义登陆态)
 * 
 * */
public class WeChatLoginHandlerInterceptor extends HandlerInterceptorAdapter{
	
	@Resource(name = "redisDaoImpl")
	private RedisDao redisDaoImpl;

	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
		// TODO Auto-generated method stub
		String path = request.getServletPath();
		if(path.matches(".*/((wechat)).*")&&!path.matches(".*/((wechat/login)).*")){
			String loginStatus = (String) request.getAttribute("loginStatus");
			String wechat = redisDaoImpl.get(loginStatus);
			if(wechat!=null){
				//刷新key的过期时间
				redisDaoImpl.expire(loginStatus, Integer.parseInt(WXProperty.get("expire_loginStatus")));
				return true;
			}else{
				return false;		
			}
		}else{
			return true;
		}
	}
	
}
